<%-- 
    Document   : zk_controlmaterials
    Created on : 2016-8-16, 17:50:48
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../../link.jsp" %>
         <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.min.js" ></script>
        <script type="text/javascript" src="${base}/js/bootstrap-datetimepicker.zh-CN.js" ></script>
        <title>质控物管理</title>
    </head>
    <style>
        tr>td{
            padding: 4px 4px 4px 4px;
            /*padding-bottom: 4px;*/
        }
        th{
            padding:4px 4px 4px 4px;
            font:bold;
            text-align:center;
        }
        .error{font-size: 1px; color: red}
    </style>
    <body style="font-family: 微软雅黑;margin-top: 10px;" ng-app="zkControl" ng-controller="mainTab">
        <div class="col-lg-12">
            <div class="panel panel-default" style="overflow: hidden">

                <div class="panel-heading"><span style="float: left">质控物列表</span>
                    <div>
                        <input  ng-model="searchContent" placeholder="质控物编号/供应商" style="width:320px; float: left;margin-left: 20px"  class="form-control input-sm" />
                        <button ng-click="getZkControls()" style="float: left" class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>

                        <button ng-click="OpenSaveModal()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-send"></span>&nbsp;&nbsp;添加</button></div>

                    <div style="clear: both"></div>
                </div>

                <table class="table table-striped table-bordered  table-hover ">
                    <thead>
                        <tr>
                            <th class="table-id">序号</th>
                            <th class="table-id">批号</th>
                            <th class="table-id">专业组</th>
                            <th class="table-id">产商</th>
                            <th class="table-id">生产日期</th>
                            <th class="table-id">有效日期</th>
                            <th class="table-set">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr  ng-repeat="control in controls" >
                            <td >{{$index}}</td>
                            <td>{{control.BATCHNUMBER}}</td>
                            <td>{{control.MAJORNAME1}}</td>
                            <td>{{control.EXFACTORY}}</td>
                            <td>{{control.PRODUCTIONTIME}}</td>
                            <td>{{control.EFFECTIVETIME}}</td>
                            <td>
                                <button ng-click="OpenUpdateModal(control)" class="btn btn-success btn-xs"><span class="fa fa-edit"></span>修改</button>
                                <button ng-click="deleteReagent(control)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>删除</button>
                            </td>
                        </tr>
                    </tbody>
                </table>  

                <footer class="panel-heading">
                    <div class="row">
                        <div style="text-align: center" >                
                            <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                        </div>
                    </div>
                </footer>

            </div>

        </div>


        <div class="modal fade mode-x" role="dialog" aria-labelledby="gridSystemModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="CloseModel()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">{{title}}质控物</h4>
                    </div>
                    <div class="modal-body">
                        <form  name="formCm" id="profile">
                            <table style="width: 100%">                             
                                <tr>

                                    <td>批号：<input type="text" name="batchnuber" ng-model="tmpControl.BATCHNUMBER" style="width: 100px" ng-minlength=1 ng-maxlength=20 required><label style="color:red;">&lowast;</label>
                                        <div class="error" ng-show="formCm.batchnuber.$dirty && formCm.batchnuber.$invalid">
                                            <small class="error" ng-show="formCm.batchnuber.$error.required">批号不能为空。</small>
                                            <small class="error" ng-show="formCm.batchnuber.$error.minlength">批号长度不能小于1</small>
                                            <small class="error" ng-show="formCm.batchnuber.$error.maxlength">批号长度不能大于20</small> 
                                        </div>
                                    </td>
                                    <td>
                                        生产日期：<input type="text" id="startdate" ng-model="tmpControl.PRODUCTIONTIME" readonly>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        产商：<input type="text" style="width: 100px" ng-model="tmpControl.EXFACTORY" >
                                    </td>
                                    <td>有效日期：<input type="text" id="effecdate" ng-model="tmpControl.EFFECTIVETIME" readonly></td>

                                </tr>
                                <tr>
                                    <td>专业组：<select ng-model="tmpControl.MAJORPK" ng-options="major.PK as major.MAJORNAME for major in majors"  style="width: 100px" ng-selected="major.PK==tmpControl.MAJORPK">  </select>
                                            
                                    </td>
                                    <td></td>
                                </tr>
                            </table>
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="CloseModel()">关闭</button>
                        <button  ng-click="saveZkControl()"   ng-disabled="formCm.$invalid" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>
                    </div>
                </div> 
            </div> 
        </div>


    </body>
    <script>
        angular.module("zkControl", ['baseModule', 'ui.bootstrap'])
                .controller("mainTab", function ($scope, base) {

                    $scope.tmpControl = {PK: ""};
                    $scope.searchContent = "";

                    $scope.data = {currentPage: 1};
                    $scope.setPage = function (pageNo) {
                        $scope.data.currentPage = pageNo;
                    };
                    $scope.pageChanged = function () {
                        $scope.getZkControls();
                    };
                    $scope.data.maxSize = 2;
                    $scope.data.bigTotalItems = 20;
                    $scope.data.bigCurrentPage = 1;
                    $scope.data.pageSize = 10;

                    $scope.getZkControls = function () {//显示

                        base.post("zkcontrol/getZkControls", {pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage, searchContent: $scope.searchContent}).get(function (data) { //参数 分页参数
//                    console.log(data);
                            if (data) {
                                $scope.controls = data.list;
                                $scope.data.bigTotalItems = data.totalRow;
//                       $scope.$apply();
                            }
                        })
                    }
                    $scope.getZkControls();
                    $scope.deleteZkControl = function (tmp) {

                        var gnl = confirm("你真的确定要删除吗?"); //友好提示
                        if (gnl == true) {
                            base.post("zkcontrol/deleteZkControl", {PK: tmp.PK}).get(function (data) {
                                if (data == 'true') {
                                    alert("删除成功", 1000);
                                    $scope.getZkControls();
                                    $scope.$apply();
                                }
                            })
                        } else {
                            return;
                        }
                    }

                    $scope.OpenSaveModal = function () {
                        $scope.title = "新增";
                        $scope.tmpControl = {PK: ""};
                        $(".mode-x").modal('show');
                    }
                    $scope.OpenUpdateModal = function (tmp) {
                        $scope.title = "修改";
                        $scope.tmpControl = tmp;
                        $(".mode-x").modal('show');
                    }
                    $scope.CloseModel = function () {//关闭窗口的同时清空窗口数据
                        $scope.tmpControl = {PK: ""};
                        $scope.getZkControls();
                    }

                    $scope.saveZkControl = function () {//必须要验证 显示序号 和扩展类型为数值

                        base.post("zkcontrol/getZkControlsRep", $scope.tmpControl).get(function (data) {
                            if (data == 'true') {
                                alert("批号在数据库中已存在", 1000);
                                return;
                            }

                            if ($scope.tmpControl.PK != "") {//修改
//                    alert(2);
                                base.post("zkcontrol/updateZkControl", $scope.tmpControl).get(function (data) {
                                    if (data == 'true') {
                                        alert("修改成功！");
                                       $scope.getZkControls();

                                    }
                                })
                            } else {//保存 
//                      alert(3);
                                base.post("zkcontrol/saveZkControl", $scope.tmpControl).get(function (data) {
                                    if (data == 'true') {
                                        alert("新增成功！");
                                       $scope.getZkControls();

                                    }
                                })
                            }

                            $(".mode-x").modal('hide');
                            $scope.CloseModel();


                        })
                    }
                    $scope.getMajors=function(){
                        base.post("zkcontrol/getMajors").get(function(data){
                            if(data){
                                $scope.majors=data;
                            }
                        })
                    }
                    $scope.getMajors();
                    $('#startdate').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
            }).on('changeDate', function (ev) {
                    $scope.startdate=ev.date.Format("yyyy-MM-dd");
                    
            });
            
             $('#effecdate').datetimepicker({
                  language: 'zh-CN',
                  format: 'yyyy-mm-dd ',
                  startView: 3,
                  autoclose: true,
                  minView: 2
            }).on('changeDate', function (ev) {
                    $scope.startdate=ev.date.Format("yyyy-MM-dd");
                    
            });
                })
    </script>
</html>
